import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsString, IsUUID, IsBoolean, IsInt, Min, IsIn } from 'class-validator';
import { Type } from 'class-transformer';
import { TaskStatus, TaskType } from '../../common/enums';

export class QueryTaskDto {
  @ApiPropertyOptional({
    description: 'Page number (1-indexed)',
    default: 1,
    minimum: 1,
  })
  @IsInt()
  @Min(1)
  @IsOptional()
  @Type(() => Number)
  page?: number = 1;

  @ApiPropertyOptional({
    description: 'Number of items per page',
    default: 10,
    minimum: 1,
  })
  @IsInt()
  @Min(1)
  @IsOptional()
  @Type(() => Number)
  pageSize?: number = 10;

  @ApiPropertyOptional({
    description: 'Filter by task status',
    enum: TaskStatus,
  })
  @IsEnum(TaskStatus)
  @IsOptional()
  status?: TaskStatus;

  @ApiPropertyOptional({
    description: 'Filter by task title (partial match)',
    example: 'Report',
  })
  @IsString()
  @IsOptional()
  title?: string;

  @ApiPropertyOptional({
    description: 'Filter by parent task ID',
    format: 'uuid',
  })
  @IsUUID()
  @IsOptional()
  parentTaskId?: string;

  @ApiPropertyOptional({
    description: 'Filter by task template ID',
    format: 'uuid',
  })
  @IsUUID()
  @IsOptional()
  taskTemplateId?: string;

  @ApiPropertyOptional({
    description: 'Filter by task types (comma-separated, e.g. "single,global")',
    example: 'single,global',
  })
  @IsString()
  @IsOptional()
  type?: string;

  @ApiPropertyOptional({
    description: 'Include deleted tasks',
    default: false,
  })
  @IsBoolean()
  @IsOptional()
  @Type(() => Boolean)
  includeDeleted?: boolean = false;

  @ApiPropertyOptional({
    description: 'Sort field',
    enum: ['createdAt', 'dueTime', 'title'],
    default: 'createdAt',
  })
  @IsIn(['createdAt', 'dueTime', 'title'])
  @IsOptional()
  sortBy?: string = 'createdAt';

  @ApiPropertyOptional({
    description: 'Sort direction',
    enum: ['ASC', 'DESC'],
    default: 'DESC',
  })
  @IsIn(['ASC', 'DESC'])
  @IsOptional()
  sortDirection?: 'ASC' | 'DESC' = 'DESC';
}
